home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-09-17 | 6.7 KB | 125 lines | [TEXT/MPS ] |
- # INIT developer helper and IPC example. Version 2.0
- # ⌐ Copyright 1990 Jeremy Grodberg. All Rights Reserved
- #
- # Development system: MPW 3.1
- #
- # Unmodified copies of this source and object code may be distributed free of charge.
- # Adaptations of this code for other development systems may be made and distributed
- # as part of said development system, otherwise, neither this code not adaptations of
- # it may be distributed along with other products for which a fee is charged.
- #
- # Apple Computer, Inc. is specifically granted non-exclusive permission to distribute
- # this code by any means, either for free, or with other code for which a fee is
- # charged, provided they do not impose further restrictions on its use, and they
- # include this entire copyright notice.
- #
- # This source is provided to make writing INITs and cdevs a little easier.
- # RegisterMySignature can also be helpful to anyone who wants to install a DRVR.
- # If you find it helpful, please send me a copy of your finished product.
- #
- # THIS SOURCE IS PROVIDE AS IS, AND ALL WARRANTIES ARE EXPLICITY DISCLAIMED.
- # BY USING THIS WORK, THE USER AGREES TO ASSUME ALL RESPONSIBILITY FOR
- # DAMAGES THAT MAY ARISE AS A RESULT, AND TO PROTECT FROM HARM ALL ENTITIES
- # INVOLVED IN THE CREATION AND DISTRIBUTION OF THIS WORK.
- #
- # Jeremy Grodberg. September, 1990
- # jgro@lia.com (via AppleLink: jgro@lia.com@INTERNET#)
- # America Online: jgro (I don't read this very often)
-
- * Changes since Version 1.0: Support for systems that do not support Gestalt
-
-
- * This is a library of code which you can use to share memory across processes.
- * While you could use this for any kind of inter-process communication, it is
- * especially intended to allow a control panel (cdev) to alter the behavior
- * of a startup document (INIT) while the latter is running (that is, without
- * restarting the computer). Entry points are defined as a Pascal functions so
- * you can call it from an Application if you want to.
- *
- * The theory behind this is that your INIT will have a block of variables which
- * it needs to use for various purposes, including storing user options.
- * The user options would be stored in a resource which is a copy of the
- * INIT's variables, and could be edited by a Control Panel Device (cdev).
- * At INIT time, the (edited) resource is copied into the INIT's variables for
- * the INIT to use. In other words, to change the user options, the user uses
- * the cdev to edit the resource, which will change the options the next time the
- * INIT is loaded.
- *
- * This is how most INITs are written, and this is why most INITs require a
- * reboot for changes to take effect. Before now, there was no simple way
- * for a cdev to get a hold of the INITs variables, so it could only communicate by
- * changing the resource and then reinitializing the INIT.
- *
- * Now with RegisterMySignature, your INIT can register itself and provide a pointer to
- * anyone that wants it. RegisterMySignature takes a selector which is an OSType, and
- * returns a longint. For your INIT, you register your INIT's creator bytes
- * (which you have cleared with Apple by registering with MacDTS) and whatever
- * longint you want, presumably the pointer to your INIT's variables. Later,
- * your cdev will call LookupMySignature with your INITs creator bytes, and get back
- * the pointer to the variables, so they can be changed in real time. It will
- * also be able to tell if the INIT was not installed, because the creator bytes
- * will not be registered. See the accompanying SampleLookup.c for an example.
- *
- * On systems that support Gestalt (System 6.0.4 and later), Gestalt is used to
- * do the actual registration and lookup. On older systems, a driver (DRVR) is
- * installed which will do the registration. The driver's source code is not
- * included, but the DRVR resource is. You don't need to do anything with the driver
- * but include it in your INIT. RegisterMySignature and LookupMySignature take
- * care of everything automatically.
- *
- * For an excellent start on how to write INITs,
- * read Technote #256, August 1990 revsion.
-
-
- # This package contains 6 files besides this one.
- # SampleINIT.a is an INIT which you can use as a template for your own INITs
- # RegisterMySignature.c registers a signature and longint for later lookup by the
- # same or another process. It uses Gestalt if available, or installs the Driver
- # contained in IPCDriver.rsrc and uses that. The Driver must be in a resource
- # file that is open when RegisterMySignature is called (such as the the INIT
- # file which calls RegisterMySignature). RegisterMySignature
- # also can be used to pass the address of shared memory between multiple
- # processes, making Inter-Process Communication available right now.
- # RegisterWithGestalt.a is a utility function which uses Gestalt to register the
- # address of the INIT's globals, for use by the INIT's cdev.
- # LookupMySignature.c contains LookupMySignature(), which is the library entry
- # for looking up the data registered by RegisterMySignature. LookupMySignature.c
- # also contains AskGestalt.c, which is the utility corresponding to
- # RegisterWithGestalt, and which is called automatically by LookupMySignature().
- # SampleLookup.c shows a very simple example of how you would use LookupMySignature
- # to get the address of the INIT's (or IPC's) memory.
- # IPCDriver.rsrc contains the DRVR resource which does the register and lookup
- # on systems that don't support Gestalt. The driver must be copied into any
- # executable file (Application, INIT, etc.) which calls RegisterMySignature.
- # The driver must be named "..ipc by jgro" and should have its SystemHeap
- # flag set.
-
- # To compile and link SampleINIT as provided, you need to have a copy of ShowINIT
- # already compiled. ShowINIT is on the Developer CD, and available elsewhere.
- # If you don't have a copy of ShowINIT, you can make the changes noted in
- # SampleINIT.a and remove ShowINIT.a.o from the link line.
-
-
-
-
- # Execute the lines below to compile and link the SampleINIT. Note that SampleINIT
- # doesn't do anything useful, so there's not much point in installing it.
- # Uncomment the -l to get a listing in <sourcefile>.lst
-
- C -b2 LookupMySignature.c
- C -b2 RegisterMySignature.c
- Asm RegisterWithGestalt.a -o RegisterWithGestalt.a.o # -l -font monaco,9
- Asm SampleINIT.a -o SampleINIT.a.o # -l -font monaco,9
-
- Link SampleINIT.a.o ShowINIT.a.o RegisterMySignature.c.o ╢
- RegisterWithGestalt.a.o "{Libraries}Interface.o" ╢
- -o SampleINIT ╢
- -m SAMPLE -sg SampleINIT -rt INIT=1 -t 'INIT' -c '????'
-
-
- # your cdev's link line would look something like this:
- #Link YourCdev.c.o SampleINIT.a.o LookupMySignature.c.o ╢
- # "{Libraries}Interface.o" ╢
- # -o SampleINIT ╢
- # -m YourCdevEntrypoint -sg YourCdevName -rt cdev=1 -t 'cdev' -c '????'
-